import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/App.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';
import 'package:huajianshe_app/widget/appbar/CAppBar.dart';
import 'package:package_info/package_info.dart';

class SettingPage extends StatefulWidget {


  @override
  State<StatefulWidget> createState() {
    return SettingPageState();
  }
}

class SettingPageState extends BaseState<SettingPage> {

  String version = '';
  @override
  void initState() {
    super.initState();
    getVersion().then((value) {
      print('$value');
      setState(() {
        this.version = value;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: CAppBar(title: '系统设置', backImgUrl: 'ic_black_arrow', overlayStyle: SystemUiOverlayStyle.dark,),
      body: Column(children: [
        ListTile(trailing: LoadImage('ic_gray_right_arrow'),
          title: Transform.translate(offset: Offset(0, -3), child: Text('账号设置', style: TS(15, C.gray333),)),
        ),
        PD(1, 15, 15),
        ListTile(trailing: Row(mainAxisSize: MainAxisSize.min, children: [
          Text('当前版本: ${version}', style: TS(14, C.grayC3),),
          W(7),
          LoadImage('ic_gray_right_arrow'),
        ]), title: Transform.translate(offset: Offset(0, -3), child: Text('当前版本', style: TS(15, C.gray333),)),
        ),
        PD(1, 15, 15),
        H(30),
        SmartButton(width: 320, height: 50, radius: 7, text: '退出账号', textColor: C.grayC3, fontSize: 15, backgroundColor: C.grayF6,
            borderColor: Color.fromRGBO(0xDD, 0xDD, 0xDD, 1), borderWidth: 1, onPressed: () { exit(context); })
      ]),
    );
  }

  Future<String> getVersion() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    return packageInfo.version;
  }

  exit(BuildContext context) {
    App.exitLogin();
    AppNavigator.push(context, RouteName.LOGIN, replace: true, clearStack: true);
  }
}